<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>WISSC轮滑教培服务网-查询系统</title>
    <#assign base=request.contextPath  />
    <link rel="icon" href="${base}/favicon.ico">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <link rel="stylesheet" href="${base}/frame/layui/css/layui.css" media="all">
    <script type="text/javascript" src="${base}/js/feng.js"></script>
    <script src="${base}/frame/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery-1.4.4.min.js"></script>
    <script src="${base}/js/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="${base}/css/hzw-city-picker.css">
    <script type="text/javascript" src="${base}/js/city-data.js"></script>
    <script type="text/javascript" src="${base}/js/hzw-city-picker.min.js"></script>
    <script type="text/javascript" src="${base}/js/city-zk.js"></script>
    <script type="text/javascript" src="${base}/js/province.js"></script>
    <style type="text/css">
        form {
            padding: 10px;
        }
    </style>
</head>
<body>
<div style="background-color: #E7141A">
    <i class="layui-icon layui-icon-shrink-right" style="color: white">&nbsp;&nbsp;&nbsp;&nbsp;信息查询</i>
</div>
<form class="layui-form" action="">
    <div class="demoTable">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">战队名称</label>
                <div class="layui-input-inline">
                    <input type="tel" id="teamName" name="teamName" lay-verify="required" autocomplete="off"
                           class="layui-input">
                </div>
            </div>

            <div class="layui-inline">
                <label class="layui-form-label">建队时间</label>
                <div class="layui-input-inline">
                    <input type="tel" id="buildingTime" name="buildingTime" lay-verify="required" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"><a style="color:red"></a>&nbsp;战队等级</label>
                <div class="layui-input-inline">
                    <select name="teamLevel" lay-verify="required" id="teamLevel" class="    ">
                        <option value="">请选择</option>
                        <option value="1">一级战队</option>
                        <option value="2">二级战队</option>
                        <option value="3">三级战队</option>
                        <option value="4">四级战队</option>
                        <option value="5">五级战队</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">选择地区</label>
                <div class="layui-input-inline">
                    <select name="provid" id="provid" onchange="provid()" lay-filter="provid">
                        <option value="">请选择国家</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <select name="cityid" id="cityid" lay-filter="cityid">
                        <option value="">请选择省</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <select name="areaid" id="areaid" lay-filter="areaid">
                        <option value="">请选择市</option>
                    </select>
                </div>
            </div>
            <button class="layui-btn " data-method="offset"
                    type="button"
                    style="background-color: #0092EF;" onclick="onSubmint()">搜索
            </button>
            <button type="reset" style="background-color: #0092EF;" onclick="chong()"
                    class="layui-btn layui-btn-primar">重置
            </button>
            <button class="layui-btn " data-method="offset"
                    type="button" style="background-color: #E7141A" onclick="deleteById()">批量删除
            </button>
        </div>
    </div>

</form>
<div style="background-color:  #E7141A;">
    <i class="layui-icon layui-icon-shrink-right" style="color: white">&nbsp;&nbsp;&nbsp;&nbsp;信息列表</i>
</div>
<table class="layui-hide" lay-filter="test" id="test" lay-size="sm"></table>
<script type="text/html" id="barDemo">

    {{#  if('${user.username}' == 'admin' && d.type==2){ }}
    <i class="layui-icon layui-icon-edit" lay-event="edit" style="font-size: 20px;"></i>&nbsp;&nbsp;&nbsp;
    <i class="layui-icon layui-icon-delete layui-btn-xs" lay-event="del" href="javascript:void(0)"
       onclick="onDelete('{{d.id}}')"
       style="font-size: 20px;"></i>
    <button class="layui-btn layui-btn-radius  " onclick="adopt('{{d.id}}')" data-method="offset" type="button"
            style="background-color: red; height: 20px ">通过
    </button>
    <button class="layui-btn layui-btn-radius  " onclick="noAdopt('{{d.id}}')" data-method="offset" type="button"
            style="background-color:red; height: 20px ">不通过
    </button>
    {{#  } else { }}
    <i class="layui-icon layui-icon-edit" lay-event="edit" style="font-size: 20px;"></i>&nbsp;&nbsp;&nbsp;
    <i class="layui-icon layui-icon-delete layui-btn-xs" lay-event="del" href="javascript:void(0)"
       onclick="onDelete('{{d.id}}')"
       style="font-size: 20px;"></i>
    {{#  } }}

</script>
<script>

    var cityPicker = new HzwCityPicker({
        data: data,
        target: 'cityChoice',
        valType: 'k',
        hideCityInput: {
            name: 'city',
            id: 'city'
        },
        hideProvinceInput: {
            name: 'areaId',
            id: 'areaId',
            val: 'q'
        },
        callback: function () {
        }
    });

    cityPicker.init();

    layui.use(['form', 'layedit', 'laydate', 'table'], function () {

        var form = layui.form
            , $ = layui.jquery
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , table = layui.table;

        var documentWith = $(document).width();

        var provid = $("#provid").val()
        var cityid = $("#cityid").val();
        var areaid = $("#areaid").val();
        //var str = areaid.replace(/^\"|\"$/g,'');
        var sum = provid + "," + cityid + "," + areaid + ",";

        var jsonData = {};

        //战队名称
        jsonData.teamName = $("#teamName").val();
        //所属地区
        jsonData.city = sum;
        //创建日期
        if ($("#buildingTime").val() != null && $("#buildingTime").val() != "") {
            jsonData.buildingTime = (new Date($("#buildingTime").val())).getTime();
        } else {
            jsonData.buildingTime = "";
        }
        //战队等级
        jsonData.teamLevel = $("#teamLevel").val();

        laydate.render({
            elem: '#birth' //指定元素
        });
        laydate.render({
            elem: '#buildingTime' //指定元素
        });
        table.render({
            elem: '#test'
            , url: '${base}/team/selectMyPage' //数据接口
            , title: '用户数据表'
            , totalRow: true
            , toolbar: '#toolbarDemo'//打印
            , cols: [[
                {type: 'checkbox'},
                {
                    field: 'id', title: '编号ID', templet: function (val) {
                        return val.LAY_INDEX
                    }, align: 'center'
                }
                , {field: 'teamName', title: '战队名称', align: 'center'}

                , {field: 'city', title: '所属地区', align: 'center'}
                , {field: 'year', title: '队龄', align: 'center'}

                , {
                    field: 'teamLevel', title: '战队等级', templet: function (val) {
                        if (val.teamLevel == "1") {
                            return "一级战队";
                        }
                        ;
                        if (val.teamLevel == "2") {
                            return "二级战队";
                        }
                        ;
                        if (val.teamLevel == "3") {
                            return "三级战队";
                        }
                        ;
                        if (val.teamLevel == "4") {
                            return "四级战队";
                        }
                        ;
                        if (val.teamLevel == "5") {
                            return "五级战队";
                        }
                        ;
                    }, align: 'center'
                }, {
                    field: 'flag', title: '审核', align: 'center', templet: function (val) {
                        if(val.flag==undefined){
                            return "";
                        };
                        if (val.flag == "4") {
                            return "当前最新数据";
                        }
                        ;
                        if (val.flag == "1") {
                            return "添加";
                        }
                        ;
                        if (val.flag == "2") {
                            return "删除";
                        }
                        ;
                        if (val.flag == "3") {
                            return "修改";
                        }
                    }, align:
                        'center'
                }
                , {
                    fixed: 'right',
                    title: '操作',
                    toolbar: '#barDemo',
                    width: 100,
                    align: 'center',
                    width: documentWith * 100 / 800
                }
            ]]
            , id: 'testReload'
            , page: {
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
                , theme: '#0092EF'
                , limit: 10
            }

        });
        $('#btn1').on('click', function () {
            var sechLin = $("#sech").val();
            var whereData = {};
        });
        var active = {
            offset: function (othis) {
                var type = othis.data('type')
                    , text = othis.text();
                layer.open({
                    type: 2,
                    title: '添加战队信息',
                    area: ['720px', '500px'],
                    shadeClose: false,
                    //弹出的页面路径
                    content: '${base}/team/team_add.html',//路径
                });
            }
        };
        $('#btn2').on('click', function () {
            var othis = $(this), method = othis.data('method');
            active[method] ? active[method].call(this, othis) : '';
        });
        //编辑
        table.on('tool(test)', function (obj) {
            var layEvent = obj.event;
            if (layEvent == "edit") {
                var data = obj.data;
                //示范一个公告层
                layer.open({
                    type: 2,
                    title: '编辑战队信息',
                    shadeClose: false,
                    area: ['100%', '100%'],
                    content: '${base}/team/team_edit.html?teamLogo=' + data.teamLogo + '&id=' + data.id,//数据接口,//数据接口
                    success: function (layero, index) {
                        var iframeWin = window[layero.find
                        ('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                        iframeWin.$("#id").val(data.id)
                        iframeWin.$("#teamName").val(data.teamName)
                        iframeWin.$("#buildingTime").val(DateFormat(data.buildingTime))
                        iframeWin.$("#cityChoice").val(data.city)
                        iframeWin.$("#teamLevel").val(data.teamLevel)
                        iframeWin.$("#cityRanking").val(data.cityRanking)
                        iframeWin.$("#provinceRanking").val(data.provinceRanking)
                        iframeWin.$("#nationalRanking").val(data.nationalRanking)

                        //渲染一下form表单
                        iframeWin.layui.form.render('select')

                    }
                });
            }
        });

    });

    // 搜索
    function onSubmint() {

        var jsonData = {};
        var provid = $("#provid").val()
        var cityid = $("#cityid").val();
        var areaid = $("#areaid").val();
        if (provid != null && provid != "" && cityid !== null && cityid != "" && areaid !== null && areaid != "") {
            var str = areaid.replace(/^\"|\"$/g, '');
            var sum = provid + "/" + cityid + "/" + str + "/";
        } else {
            var provid = $("#provid").val()
            var cityid = $("#cityid").val();
            var areaid = $("#areaid").val();
        }

        //战队名称
        jsonData.teamName = $("#teamName").val();
        //所属地区
        jsonData.city = sum;
        //创建日期
        if ($("#buildingTime").val() != null && $("#buildingTime").val() != "") {
            jsonData.buildingTime = (new Date($("#buildingTime").val())).getTime();
        } else {
            jsonData.buildingTime = "";
        }
        //战队等级
        jsonData.teamLevel = $("#teamLevel").val();

        var table = layui.table;
        //表刷新方法
        table.reload('testReload', {
            url: '${base}/team/selectMyPage'//数据接口
            , where: jsonData
            //设定异步数据接口的额外参数
        });
    }

    //删除
    function onDelete(id) {
        layer.confirm('真的要删除吗?', function (index) {
            var data = {};
            data.id = id;
            $.ajax({
                type: "POST",
                contentType: "application/json;charset=UTF-8",
                url: "${base}/team/teamDelete",
                data: JSON.stringify(data),
                sync: false,
                success: function (data) {
                    //alert("删除成功")
                    var table = layui.table;
                    //表刷新方法
                    table.reload('testReload', {
                        url: '${base}/team/selectMyPage'
                        , where: {} //设定异步数据接口的额外参数
                    });
                    //关闭删除是否删除的提示框
                    layer.close(index);
                }
            });
        });
    }

    //批量删除
    function deleteById() {

        var table = layui.table;
        var checkStatus = table.checkStatus('testReload')
        var data = checkStatus.data;
        var ids = [];
        var a = "";
        for (var i = 0; i < data.length; i++) {
            ids.push(data[i].id)
            a += "," + data[i].id
        }
        if (ids.length === 0) {
            layer.msg("请选择一个呗");
            return;
        }
        $.ajax({
            type: "POST",
            url: "${base}/team/deleteBtId",
            data: {ids: a},
            sync: false,
            success: function (data) {
                layer.msg("删除成功")
                var table = layui.table;
                //表刷新方法
                table.reload('testReload', {
                    url: '${base}/team/selectMyPage'//数据接口
                    , where: {} //设定异步数据接口的额外参数
                    //,height: 300
                });
            }
        });
    }

    /*alert(1)
    $('#provid').click(function(event){
        alert(2)
        /!*$("#cityid option[value='0']").after('<option value=" ">test</option>');*!/
       // var a =  document.getElementById("cityid");
       // a.append("<option>sssssss</option>");

        $("#cityid").html("<option>sssssss</option>");

    })*/

    /*window.onload = function () {
        $("#cityid").append("<option value=''>sssssss</option>");
    }*/


</script>
</body>
<script>
    //把重置添加一个点击事件点击重置刷新页面
    function chong() {
        window.location.reload();
    }

    //通过
    function adopt(id) {
        var jsonDate = {};
        jsonDate.id = id;
        $.ajax({
            type: "POST",
            contentType: "application/json;charset=UTF-8",
            url: "${base}/team/adopt",
            data: JSON.stringify(jsonDate),
            sync: false,
            success: function (data) {
                layer.msg("已通过")
                var table = layui.table;
                //表刷新方法
                table.reload('testReload', {
                    url: '${base}/team/selectMyPage'//数据接口
                    , where: {} //设定异步数据接口的额外参数
                    //,height: 300
                });
            }
        });
    }


    //不通过
    function noAdopt(id) {
        var jsonDate = {};
        jsonDate.id = id;
        $.ajax({
            type: "POST",
            contentType: "application/json;charset=UTF-8",
            url: "${base}/team/noAdopt",
            data: JSON.stringify(jsonDate),
            sync: false,
            success: function (data) {
                layer.msg("不通过")
                var table = layui.table;
                //表刷新方法
                table.reload('testReload', {
                    url: '${base}/team/selectMyPage'//数据接口
                    , where: {} //设定异步数据接口的额外参数
                    //,height: 300
                });
            }
        });
    }

</script>
</html>